<?php
/**
 * Created by PhpStorm.
 * User: insgeek
 * Date: 2017/2/10
 * Time: 15:33
 * 简单工厂：延迟到子类中去创建对象
 */
namespace DesignPattern\FactorPattern;

class Button
{/* ...*/
}

class WinButton extends Button
{/* ...*/
}

class MacButton extends Button
{/* ...*/
}

interface ButtonFactory
{
    public function createButton($type);
}

class MyButtonFactory implements ButtonFactory
{
    // 实现工厂方法
    public function createButton($type)
    {
        switch ($type) {
            case 'Mac':
                return new MacButton();
            case 'Win':
                return new WinButton();
        }
    }
}

$button_obj = new MyButtonFactory();
var_dump($button_obj->createButton('Mac'));
var_dump($button_obj->createButton('Win'));